<?php 
require_once('config/config.php');
require_once('checked.php'); //判断是否登录   


//判断是不是post请求
if($_POST){
  // 获取表单提交的值
  $username = isset($_POST['username']) ? trim($_POST['username']) :'';
  $password = isset($_POST['password']) ? trim($_POST['password']) :'';
  $createtime = isset($_POST['createtime']) ? trim($_POST['createtime']) :  '';
 
  // 判断入职时间
  if(empty($createtime)){
    $createtime = time();
  }else{
    // 将字符串转化成标准时间
    $createtime = strtotime($createtime);
  }
  //先写出密码盐
  $str = randstr();
  //加密
  $encrypt = md5( $str.$password);
  // 封装数据
  $data = [
    "username"=> $username,
    "password"=>  $encrypt,
    "createtime"=> $createtime,
    "salt"=>$str
  ];
 //给表名
 $table = 'admin';

 //书写添加的方法
 $i =  insert($table,$data);
 if($i){
   notice('添加管理员信息成功!','AdminList.php');
   exit;
 }else{
   notice('添加管理员信息失败!');
   exit;
 }

}
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <?php require_once('meta.php') ?>
  </head>
  
  <body>
    <!-- 头部 -->
    <?php require_once('header.php') ?>
    
    <div class="sidebar-nav">
        <a href="#dashboard-menu" class="nav-header" data-toggle="collapse"><i class="icon-dashboard"></i>控制面板</a>
        <ul id="dashboard-menu" class="nav nav-list collapse in">
            <li><a href="index.php">首页</a></li>
            <li><a href="list.php">管理员管理</a></li>
        </ul>
    </div>

    <div class="content">
        <div class="header">
            <h1 class="page-title">管理员添加</h1>
        </div>
        <ul class="breadcrumb">
            <li><a href="index.php">Home</a> <span class="divider">/</span></li>
            <li class="active">Index</li>
        </ul>

        <div class="container-fluid">
            <div class="row-fluid">
                    
                <div class="btn-toolbar">
                    <button class="btn btn-primary" onClick="location='AdminList.php'"><i class="icon-list"></i> 管理员列表</button>
                  <div class="btn-group">
                  </div>
                </div>

                <div class="well">
                    <div id="myTabContent" class="tab-content">
                      <div class="tab-pane active in" id="home">
                        <form method="post" enctype="multipart/form-data">  
                            <label>管理员姓名</label>
                            <input type="text" name="username" value="" placeholder="请输入姓名" class="input-xxlarge" required>
                            
                            <label>密码</label>
                            <input type="text" name="password" value="" placeholder="请输入邮箱" class="input-xxlarge" required>
                         
                            <label>入职时间</label>
                            <input type="date" name="createtime" value="<?php echo date("Y-m-d", time()) ?>" class="input-xxlarge">
                         
                            <label></label>
                            <input class="btn btn-primary" type="submit" value="提交" />
                        </form>
                      </div>
                  </div>
                </div>

                <div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h3 id="myModalLabel">Delete Confirmation</h3>
                  </div>
                  <div class="modal-body">
                    
                    <p class="error-text"><i class="icon-warning-sign modal-icon"></i>Are you sure you want to delete the user?</p>
                  </div>
                  <div class="modal-footer">
                    <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
                    <button class="btn btn-danger" data-dismiss="modal">Delete</button>
                  </div>
                </div>
                
                <footer>
                    <hr>
                    <p>&copy; 2017 <a href="#" target="_blank">copyright</a></p>
                </footer>
                    
            </div>
        </div>
    </div>
  </body>
</html>